Microprocessor with random number generator and instruction for storing random data

ABSTRACT

A microprocessor that includes a random number generator (RNG) and an instruction for storing random data bytes generated by the generator. The RNG includes multiple buffers for buffering the random bytes and counters associated with each buffer for keeping a count of the number of bytes in each buffer. The instruction specifies a destination for the bytes to be stored to. In one embodiment, the number of bytes written to memory is variable and is the number of bytes available when the instruction is executed; in another, the instruction specifies the number. If variable, the instruction atomically stores a count specifying the number of valid bytes actually stored. In one embodiment the destination is a location in system memory. The count may be stored to memory with the bytes; or the count may be stored to a user-visible register. An x86 REP prefix may be used.

CROSS REFERENCE TO RELATED APPLICATIONS

This application is a divisional of U.S. patent application Ser. No.10/300,922 (Docket CNTR.2165), filed on Nov. 20, 2002, which claimspriority to U.S. Provisional Application No. 60/334,281, filed Nov. 20,2001.

This application is related to the following U.S. Patent and PatentApplications: Number Filing Date Docket Number Title 6,871,206 Nov. 20,2002 CNTR.2068 CONTINUOUS MULTI-BUFFERING RANDOM NUMBER GENERATOR10/300933 Nov. 20, 2002 CNTR.2065 RANDOM NUMBER GENERATOR BIT STRINGFILTER 10/300931 Nov. 20, 2002 CNTR.2069 MICROPROCESSOR INCLUDING RANDOMNUMBER GENERATOR SUPPORTING OPERATING SYSTEM- INDEPENDENT MULTITASKINGOPERATION 10/300931 Nov. 04, 2005 CNTR.2069-CP1 CONTINUOUSMULTI-BUFFERING RANDOM NUMBER GENERATOR 10/300922 Nov. 20, 2002CNTR.2165 RANDOM NUMBER GENERATOR WITH SELF-TYPING DATA concurrentlyCNTR.2069-D1 MICROPROCESSOR INCLUDING herewith RANDOM NUMBER GENERATORSUPPORTING OPERATING SYSTEM- INDEPENDENT MULTITASKING OPERATION10/365601 Feb. 11, 2003 CNTR.2166 RANDOM NUMBER GENERATOR WITHSELECTABLE DUAL RANDOM BIT STRING ENGINES 10/365599 Feb. 11, 2003CNTR.2167 MICROPROCESSOR WITH SELECTIVELY AVAILABLE RANDOM NUMBERGENERATOR BASED ON SELF-TEST RESULT 10/365600 Feb. 11, 2003 CNTR.2214APPARATUS AND METHOD FOR REDUCING SEQUENTIAL BIT CORRELATION IN A RANDOMNUMBER GENERATOR

BACKGROUND OF THE INVENTION Field of the Invention

This invention relates in general to the field of random numbergeneration, and particularly to a random number generator within amicroprocessor.

Historically, many computer software applications require a supply ofrandom numbers. For example, Monte Carlo simulations of physicalphenomena, such as large-scale weather simulations, require a supply ofrandom numbers in order to simulate physical phenomenon. Other examplesof applications requiring random numbers are casino games and on-linegambling to simulate card shuffling, dice rolling, etc.; lottery numbercreation; the generation of data for statistical analysis, such as forpsychological testing; and use in computer games.

The quality of randomness needed, as well as the performancerequirements for generating random numbers, differs among these types ofapplications. Many applications such as computer games have trivialdemands on quality of randomness. Applications such as psychologicaltesting have more stringent demands on quality, but the performancerequirements are relatively low. Large-scale Monte Carlo-basedsimulations, however, have very high performance requirements andrequire good statistical properties of the random numbers, althoughnon-predictability is not particularly important. Other applications,such as on-line gambling, have very stringent randomness requirements aswell as stringent non-predictability requirements.

While these historical applications are still important, computersecurity generates the greatest need of high-quality random numbers. Therecent explosive growth of PC networking and Internet-based commerce hassignificantly increased the need for a variety of security mechanisms.

High-quality random numbers are essential to all major components ofcomputer security, which are confidentiality, authentication, andintegrity.

Data encryption is the primary mechanism for providing confidentiality.Many different encryption algorithms exist, such as symmetric,public-key, and one-time pad, but all share the critical characteristicthat the encryption/decryption key must not be easily predictable. Thecryptographic strength of an encryption system is essentially thestrength of the key, i.e., how hard it is to predict, guess, orcalculate the decryption key. The best keys are long truly randomnumbers, and random number generators are used as the basis ofcryptographic keys in all serious security applications.

Many successful attacks against cryptographic algorithms have focusednot on the encryption algorithm but instead on its source of randomnumbers. As a well-known example, an early version of Netscape's SecureSockets Layer (SSL) collected data from the system clock and process IDtable to create a seed for a software pseudo-random number generator.The resulting random number was used to create a symmetric key forencrypting session data. Two graduate students broke this mechanism bydeveloping a procedure for accurately guessing the random number toguess the session key in less than a minute.

Similar to decryption keys, the strength of passwords used toauthenticate users for access to information is effectively how hard itis to predict or guess the password. The best passwords are long trulyrandom numbers. In addition, in authentication protocols that use achallenge protocol, the critical factor is for the challenge to beunpredictable by the authenticating component. Random numbers are usedto generate the authentication challenge.

Digital signatures and message digests are used to guarantee theintegrity of communications over a network. Random numbers are used inmost digital signature algorithms to make it difficult for a maliciousparty to forge the signature. The quality of the random number directlyaffects the strength of the signature. In summary, good securityrequires good random numbers.

Numbers by themselves are not random. The definition of randomness mustinclude not only the characteristics of the numbers generated, but alsothe characteristics of the generator that produces the numbers.Software-based random number generators are common and are sufficientfor many applications. However, for some applications softwaregenerators are not sufficient. These applications require hardwaregenerators that generate numbers with the same characteristics ofnumbers generated by a random physical process. The importantcharacteristics are the degree to which the numbers produced have anon-biased statistical distribution, are unpredictable, and areirreproducible.

Having a non-biased statistical distribution means that all values haveequal probability of occurring, regardless of the sample size. Almostall applications require a good statistical distribution of their randomnumbers, and high-quality software random number generators can usuallymeet this requirement. A generator that meets only the non-biasedstatistical distribution requirement is called a pseudo-random numbergenerator.

Unpredictability refers to the fact that the probability of correctlyguessing the next bit of a sequence of bits should be exactly one-half,regardless of the values of the previous bits generated. Someapplications do not require the unpredictability characteristic;however, it is critical to random number uses in security applications.If a software generator is used, meeting the unpredictabilityrequirement effectively requires the software algorithm and its initialvalues be hidden. From a security viewpoint, a hidden algorithm approachis very weak. Examples of security breaks of software applications usinga predictable hidden algorithm random number generator are well known. Agenerator that meets both the first two requirements is called acryptographically secure pseudo-random number generator.

In order for a generator to be irreproducible, two of the samegenerators, given the same starting conditions, must produce differentoutputs. Software algorithms do not meet this requirement. Only ahardware generator based on random physical processes can generatevalues that meet the stringent irreproducibility requirement forsecurity. A generator that meets all three requirements is called atruly random number generator.

Software algorithms are used to generate most random numbers forcomputer applications. These are called pseudo-random number generatorsbecause the characteristics of these generators cannot meet theunpredictability and irreproducibility requirements. Furthermore, somedo not meet the non-biased statistical distribution requirements.

Typically, software generators start with an initial value, or seed,sometimes supplied by the user. Arithmetic operations are performed onthe initial seed to produce a first random result, which is then used asthe seed to produce a second result, and so forth. Software generatorsare necessarily cyclical. Ultimately, they repeat the same sequence ofoutput. Guessing the seed is equivalent to being able to predict theentire sequence of numbers produced. The irreproducibility is only asgood as the secrecy of the algorithm and initial seed, which may be anundesirable characteristic for security applications. Furthermore,software algorithms are reproducible because they produce the sameresults starting with the same input. Finally, software algorithms donot necessarily generate every possible value within the range of theoutput data size, which may reflect poorly in the non-biased statisticaldistribution requirement.

A form of random number generator that is a hybrid of softwaregenerators and true hardware generators are entropy generators. Entropyis another term for unpredictability. The more unpredictable the numbersproduced by a generator, the more entropy it has. Entropy generatorsapply software algorithms to a seed generated by a physical phenomenon.For example, a highly used PC encryption program obtains its seed byrecording characteristics of mouse movements and keyboard keystrokes forseveral seconds. These activities may or may not generate poor entropynumbers, and usually require some user involvement. The most undesirablecharacteristic of most entropy generators is that they are very slow toobtain sufficient entropy.

It should be clear from the foregoing that certain applications,including security applications, require truly random numbers which canonly be generated by a random physical process, such as the thermalnoise across a semiconductor diode or resistor, the frequencyinstability of a free-running oscillator, or the amount a semiconductorcapacitor is charged during a particular time period. These types ofsources have been used in several commercially available add-in randomnumber generator devices, such as PCI cards and serial bus devices. Noneof these devices have enjoyed much commercial use, apparently becausethey are either relatively slow or relatively expensive.

One recently developed inexpensive solution is the hardware randomnumber generator in the Intel Firmware Hub 82802 part, which usesthermal noise to generate random numbers. The Firmware Hub is a chip inthe chipset of a computer system that includes flash memory for storingsystem firmware, such as a system BIOS. When the system processorrequires a byte of random data, the processor polls a bit in a statusregister in the Firmware Hub. The Firmware Hub sets the bit to indicatea byte of random data is available. Once the bit is set, the processorreads a random data byte from another register in the Firmware Hub. Ifan application requires a large number of random data bytes, theapplication continues to poll the bit in the status register untilanother byte is ready and then reads the next byte. The applicationrepeats this process until it has accumulated the desired number ofrandom data bytes.

One solution to providing an inexpensive, high-performance hardwarerandom number generator would be to incorporate it within amicroprocessor. The random number generator could utilize randomphysical process sources such as those discussed above, and would berelatively inexpensive, since it would be incorporated into an alreadyexisting semiconductor die. Such a microprocessor would need a way toprovide the random data bytes to the application. It would be desirablefor the means of providing the random data bytes to be efficient for theapplication. Furthermore, it would be desirable for the means ofproviding the random data bytes to function correctly in a multi-taskingenvironment so that multiple applications running the computer systemcould share the random number generator feature.

SUMMARY OF THE INVENTION

The present invention provides a microprocessor that includes a randomnumber generator and an instruction for storing random numbers generatedby the generator to a destination specified by the instruction.Accordingly, in attainment of the aforementioned object, it is a featureof the present invention to provide a macroinstruction executable by amicroprocessor for storing random numbers from the microprocessor to amemory coupled to the microprocessor. The instruction includes an opcodeand a first field that stores a first operand. The first operandspecifies an address in the memory for storing zero or more bytes ofrandom data generated by a random number generator comprised in themicroprocessor. The macroinstruction also includes a second field thatstores a second operand. The second operand specifies a registercomprised in the microprocessor. The register stores the zero or morebytes of random data to be stored in the memory.

In another aspect, it is a feature of the present invention to provide amicroprocessor that has a memory coupled to it. The microprocessorincludes a storage element that accumulates a variable number of bytesof random data. The microprocessor also includes an instructiontranslator, coupled to the storage element, which translates aninstruction specifying an address in the memory. The microprocessor alsoincludes a store unit, coupled to the storage element, which stores tothe memory at the address the variable number of bytes of random datafrom the storage element in response to the instruction translatortranslating the instruction.

In another aspect, it is a feature of the present invention to provide amicroprocessor for running a multitasking operating system. Themicroprocessor is coupled to a system memory. The microprocessorincludes a random number generator (RNG) that has a buffer foraccumulating between zero and N inclusive bytes of random data, where Nis greater than one. The microprocessor also includes a counter formaintaining a count of the bytes accumulated in the buffer. Themicroprocessor also includes an instruction translator, coupled to theRNG, which translates an instruction instructing the microprocessor tostore the bytes accumulated in the buffer to the system memory.

In another aspect, it is a feature of the present invention to provide amicroprocessor for running a multitasking operating system. Themicroprocessor has a plurality of user-visible registers. Themicroprocessor includes a random number generator (RNG) that has abuffer for accumulating between zero and N inclusive bytes of randomdata, wherein N is greater than one. The microprocessor also includes acounter for keeping a count of the bytes accumulated in the buffer. Themicroprocessor also includes an instruction translator, coupled to theRNG, which translates an instruction instructing the microprocessor tostore the bytes accumulated in the buffer to one of the plurality ofuser-visible registers.

In another aspect, it is a feature of the present invention to provide amicroprocessor that has a plurality of user-visible registers. Themicroprocessor includes a random number generator (RNG) that generatesbytes of random data. The microprocessor also includes an instructiontranslator, coupled to the RNG, which translates an instruction of themicroprocessor instruction set. The instruction includes an opcode and adestination operand for use in specifying a destination for storing anumber of the bytes of random data generated by the RNG. The number isspecified in one of the plurality of user-visible registers in themicroprocessor.

In another aspect, it is a feature of the present invention to provide amicroprocessor for running a multitasking operating system. Themicroprocessor includes a random number generator (RNG) that has abuffer that accumulates a variable number of random data bytes and acounter that counts the variable number of accumulated bytes. Themicroprocessor also includes an instruction translator, coupled to theRNG, which translates an instruction of the microprocessor instructionset. The instruction stores a count from the counter and the accumulatedbytes from the buffer to a memory coupled to the microprocessor. Themicroprocessor also includes an interrupt unit, coupled to theinstruction translator, which disables interrupts of the microprocessorafter the instruction translator translates the instruction and enablesinterrupts after execution of the instruction.

An advantage of the present invention is that, unlike prior methods thatrequire polling a status bit to determine when random data is available,embodiments of the present invention immediately provide the random datathat is available. Another advantage is that in some embodiments theinstruction provided is atomic and therefore inherently supportsmultitasking. Another advantage is that in some embodiments theinstruction provided has self-typing data since both the count and therandom data bytes are written together to memory. This is beneficialsince most of the embodiments allow the instruction to store a variablenumber of random data bytes.

Other features and advantages of the present invention will becomeapparent upon study of the remaining portions of the specification anddrawings.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram illustrating a microprocessor according to thepresent invention.

FIG. 2 is a block diagram illustrating the RNG unit of themicroprocessor of FIG. 1 according to the present invention.

FIG. 3 is a block diagram illustrating various registers in themicroprocessor of FIG. 1 related to the RNG unit of FIG. 1 according tothe present invention.

FIG. 4 is a flowchart illustrating operation of the microprocessor ofFIG. 1 when executing an instruction that loads a value into the XMM0register of FIG. 3 according to the present invention.

FIG. 5 is a block diagram illustrating operation of the microprocessorof FIG. 1 when executing an XLOAD instruction according to the presentinvention.

FIG. 6 is a flowchart illustrating operation of the microprocessor ofFIG. 1 when executing an XLOAD instruction according to the presentinvention.

FIG. 7 is a block diagram illustrating operation of the microprocessorof FIG. 1 when executing an XSTORE instruction according to the presentinvention.

FIG. 8 is a flowchart illustrating operation of the microprocessor ofFIG. 1 when executing an XSTORE instruction according to the presentinvention.

FIG. 9 is a flowchart illustrating an example of multi-tasking operationof the microprocessor of FIG. 1 with respect to random number generationaccording to the present invention.

FIG. 10 is a block diagram illustrating the string filter of the RNGunit of FIG. 2 of the microprocessor of FIG. 1 according to the presentinvention.

FIG. 11 is a flowchart illustrating operation of the string filter ofFIG. 10 according to the present invention.

FIG. 12 is a block diagram illustrating operation of the microprocessorof FIG. 1 when executing an XSTORE instruction according to an alternateembodiment of the present invention.

FIG. 13 is a flowchart illustrating multi-buffering operation of the RNGunit of FIG. 2 according to the present invention.

FIG. 14 is a flowchart illustrating operation of the microprocessor ofFIG. 1 when executing an XLOAD instruction according to an alternateembodiment of the present invention.

FIG. 15 is a flowchart illustrating operation of the microprocessor ofFIG. 1 when executing an XSTORE instruction according to an alternateembodiment of the present invention.

FIGS. 16 and 17 are block diagrams illustrating operation of themicroprocessor of FIG. 1 when executing an XSTORE instruction accordingto alternate embodiments of the present invention.

DETAILED DESCRIPTION OF THE INVENTION

Referring now to FIG. 1, a block diagram illustrating a microprocessor100 according to the present invention is shown. Microprocessor 100 ofFIG. 1 is a pipelined microprocessor comprising multiple stages, each ofwhich performs a portion of the execution of program instructions asdescribed below.

Microprocessor 100 includes a random number generator (RNG) unit 136.Microprocessor 100 executes operating systems and application programsthat may require a supply of random numbers for various functions suchas data encryption, simulations of physical phenomena, statisticalanalysis, or numerical analysis, among others. RNG unit 136 generatesrandom numbers for these uses. RNG unit 136 will be described in moredetail below.

Microprocessor 100 also includes an instruction cache 102. Instructioncache 102 caches program instructions fetched from a system memorycoupled to microprocessor 100.

Microprocessor 100 also includes an instruction fetcher 104 coupled toinstruction cache 102. Instruction fetcher 104 controls the fetching ofthe instructions from the system memory and/or instruction cache 102.Instruction fetcher 104 selects a value for an instruction pointermaintained by microprocessor 100. The instruction pointer specifies thenext memory address from which to fetch instructions. Normally theinstruction pointer is sequentially incremented to the next instruction.However, control flow instructions, such as branches, jumps, subroutinecalls and returns, may cause the instruction pointer to be updated to anon-sequential memory address specified by the control flow instruction.In addition, interrupts may cause the instruction fetcher 104 to updatethe instruction pointer to a non-sequential address.

Microprocessor 100 also includes an interrupt unit 146 coupled toinstruction fetcher 104. Interrupt unit 146 receives an interrupt signal148 and an interrupt vector 152. An entity external to microprocessor100 may assert the interrupt signal 148 and provide an interrupt vector152 to cause microprocessor 100 to execute an interrupt service routine.Interrupt unit 146 determines the memory address of an interrupt serviceroutine based on the interrupt vector 152 and provides the interruptservice routine memory address to instruction fetcher 104, which updatesthe instruction pointer to the interrupt service routine address.Interrupt unit 146 also selectively disables and enables interruptservicing depending upon the particular instructions being executed bymicroprocessor 100. That is, if interrupts are disabled, then theinstruction pointer will not be changed even though interrupt line 148is asserted until interrupts are enabled.

Microprocessor 100 also includes an instruction translator 106 coupledto instruction fetcher 104, interrupt unit 146, and RNG unit 136.Instruction translator 106 translates instructions received frominstruction cache 102 and/or system memory. Instruction translator 106translates the instructions and takes appropriate actions based on thetype of instruction translated. Instruction translator 106 translatesinstructions defined in the instruction set of microprocessor 100.Instruction translator 106 generates an illegal instruction exception ifit translates an instruction that is not defined in the instruction setof microprocessor 100.

In one embodiment, the instruction set of microprocessor 100 issubstantially similar to the instruction set of an Intel® Pentium III®or Pentium IV® microprocessor. However, advantageously microprocessor100 of the present invention includes additional instructions relatingto the generation of random numbers by RNG unit 136. One additionalinstruction is an XSTORE instruction that stores random numbersgenerated by RNG unit 136. Another additional instruction is an XLOADinstruction that loads control values from system memory into a controland status register (CSR) 226 in RNG unit 136 and into a Streaming SIMDExtensions (SSE) register XMM0 372, which are described below withrespect to FIGS. 2 and 3. The XSTORE and XLOAD instructions aredescribed in more detail below.

Additionally, instruction translator 106 provides information abouttranslated instructions to interrupt unit 146 to enable interrupt unit146 to appropriately enable and disable interrupts. Furthermore,instruction translator 106 provides information about translatedinstructions to RNG unit 136. For example, instruction translator 106provides information to RNG unit 136 about translated XSTORE and XLOADinstructions. In addition, instruction translator 106 informs RNG unit136 when an instruction is translated that loads values into SSEregister XMM0 372, in response to which RNG unit 136 takes certainactions, such as setting a flag to indicate the possible occurrence of atask switch by the operating system, as described below.

In one embodiment, instruction translator 106 translates amacroinstruction, such as a Pentium III or IV instruction, into one ormore microinstructions that are executed by the microprocessor 100pipeline.

Microprocessor 100 also includes a microcode ROM 132 coupled toinstruction translator 106. Microcode ROM 132 stores microcodeinstructions for provision to instruction translator 106 to be executedby microprocessor 100. Some of the instructions in the instruction setof microprocessor 100 are implemented in microcode. That is, wheninstruction translator 106 translates one of these instructions,instruction translator 106 causes a routine of microinstructions withinmicrocode ROM 132 to be executed to perform the translatedmacroinstruction. In one embodiment, the XSTORE and/or XLOADinstructions are implemented in microcode. Additionally, in oneembodiment, the XSTORE and XLOAD instructions are atomic because theyare uninterruptible. That is, interrupts are disabled during theexecution of XSTORE and XLOAD instructions.

Microprocessor 100 also includes a register file 108 coupled toinstruction translator 106. Register file 108 includes the user-visibleregisters of microprocessor 100, among others. In one embodiment, theuser-visible registers of register file 108 include the user-visibleregister set of a Pentium III or IV. SSE registers 352 of FIG. 3 areincluded in register file 108. SSE registers 352 are used by an SSE unit134 included in microprocessor 100 and by RNG unit 136, as describedbelow. In particular, register file 108 includes registers that areknown to contemporary operating systems. Consequently, when an operatingsystem switches from a first task to a second task, the operating systemsaves to system memory the registers in register file 108, including SSEregisters 352, for the first task and restores from system memory theregisters in register file 108, including SSE registers 352, for thesecond task.

Microprocessor 100 also includes an address generator 112 coupled toregister file 108. Address generator 112 generates memory addressesbased on operands stored in register file 108 and based on operandssupplied by the instructions translated by instruction translator 106.In particular, address generator 112 generates a memory addressspecifying the location in system memory to which an XSTORE instructionstores bytes of random data. Additionally, address generator 112generates a memory address specifying the location in system memory fromwhich an XLOAD instruction loads control values for storage in CSR 226of FIG. 2 via a data bus 142.

Microprocessor 100 also includes a load unit 114 coupled to addressgenerator 112. Load unit 114 loads data from the system memory intomicroprocessor 100. Load unit 114 also includes a data cache that cachesdata read from the system memory. Load unit 114 loads data for provisionto execution units in microprocessor 100, such as SSE unit 134, RNG unit136 and execution units included in execute stage 116, on data bus 142.In particular, load unit 114 loads control values from system memory forstorage in CSR 226 of FIG. 2 to execute an XLOAD instruction.

Microprocessor 100 also includes execute stage 116 coupled to load unit114 via data bus 142. Execute stage 116 includes execution units such asarithmetic logic units for performing arithmetical and logicaloperations, such as adds, subtracts, multiplies, divides, and Booleanoperations. In one embodiment, execute stage 116 includes an integerunit for performing integer operations and a floating-point unit forperforming floating-point operations.

Microprocessor 100 also includes SSE unit 134 coupled to load unit 114and instruction translator 106. SSE unit 134 includes arithmetic andlogic units for executing SSE instructions, such as those included inthe Pentium III and IV SSE or SSE2 instruction set. In one embodiment,although SSE registers 352 of FIG. 3 are included conceptually inregister file 108, they are physically located in SSE unit 134 forstoring operands used by SSE unit 134.

Microprocessor 100 also includes RNG unit 136 coupled to instructiontranslator 106 and to load unit 114 via data bus 142. RNG unit 136provides on a data bus 144 the random data bytes and a count specifyingthe number of random data bytes provided for an XSTORE instruction. RNGunit 136 will be described in more detail below with respect to theremaining Figures.

Microprocessor 100 also includes a store unit 118 coupled to executeunit 116, SSE unit 134, and RNG unit 136. Store unit 118 stores data tothe system memory and the data cache of load unit 114. Store unit 118stores results generated by execute unit 116, SSE unit 134, and RNG unit136 to system memory. In particular, store unit 118 stores XSTOREinstruction count and random data bytes provided on data bus 144 by RNGunit 136 to system memory.

Microprocessor 100 also includes a write-back unit 122 coupled toexecute unit 116 and register file 108. Write-back unit 122 writes backinstruction results to register file 108.

Microprocessor 100 also includes write buffers 124 coupled to write-backunit 122. Write buffers 124 hold data waiting to be written to systemmemory, such as XSTORE instruction count and data.

Microprocessor 100 also includes a bus interface unit (BIU) 128 coupledto write buffers 124. BIU 128 interfaces microprocessor 100 with aprocessor bus 138. Processor bus 138 couples microprocessor 100 to thesystem memory. BIU 128 performs bus transactions on processor bus 138 totransfer data between microprocessor 100 and system memory. Inparticular, BIU 128 performs one or more bus transactions on processorbus 138 to store XSTORE instruction count and data to system memory.Additionally, BIU 128 performs one or more bus transactions on processorbus 138 to load XLOAD instruction control values from system memory.

Microprocessor 100 also includes read buffers 126 coupled to BIU 128 andregister file 108. Read buffers 126 hold data received from systemmemory by BIU 128 while waiting to be provided to load unit 114 orregister file 108. In particular, read buffers 126 hold XLOADinstruction data received from system memory while waiting to beprovided to load unit 114 and subsequently to RNG unit 136.

Referring now to FIG. 2, a block diagram illustrating RNG unit 136 ofmicroprocessor 100 of FIG. 1 according to the present invention isshown.

RNG unit 136 includes control logic 244. Control logic 244 includes alarge amount of combinatorial and sequential logic for controllingvarious elements of RNG unit 136. Control logic 244 receives an xloadsignal 272 and an xstore signal 268 that indicate an XLOAD or XSTOREinstruction, respectively, is being executed. Control logic 244 alsoreceives a reset signal 248 that indicates RNG unit 136 is being reset.Control logic 244 is described below in detail in connection with theremainder of RNG unit 136.

RNG unit 136 also includes a self-test unit 202 coupled to control logic244. Self-test unit 202 receives a self-test enable signal 292 from acontrol and status register, referred to as machine specific register(MSR) 212, which is described in more detail with respect to FIG. 3below. MSR 212 is also coupled to control logic 244. Self-test unit 202provides a self-test fail signal 288 to control logic 244. Self-testunit 202 performs various self-tests of RNG unit 136 if enabled byself-test enable signal 292. If the self-tests fail, self-test unit 202generates a true value on self-test fail signal 288, which is alsoprovided to MSR 212. In one embodiment, self-test unit 202 performsstatistical random number generator tests as defined by the FederalInformation Processing Standards (FIPS) Publication 140-2 at pages35-36, which are hereby incorporated by reference.

In one embodiment, self-test unit 202 performs the self-tests upondemand by a user. In one embodiment, self-test unit 202 performs theself-tests after a reset of microprocessor 100. If the self-tests fail,either on demand or on reset, self-test unit 202 generates a true valueon self-test fail signal 288, which is reflected in a self-test failedbit 318 of FIG. 3 of MSR 212. Control logic 244 examines the self-testfailed bit 318 on reset. If the self-test failed bit 318 is true, thencontrol logic 244 asserts a false value on an RNG present signal 286that is provided to MSR 212 for updating an RNG present bit 314 of FIG.3.

RNG present signal 286 is also provided to a CPUID register 204 thatincludes an RNG present bit 302 of FIG. 3 that is also updated by RNGpresent signal 286. That is, RNG present bit 302 of CPUID register 204is a copy of RNG present bit 314 of MSR 212. In one embodiment, anapplication program may read CPUID register 204 by executing a CPUIDinstruction in the IA-32 instruction set. If RNG present bit 302 isfalse, then microprocessor 100 indicates that RNG unit 136 is notpresent and the random number generation features of microprocessor 100are not available. Advantageously, an application requiring randomnumbers may detect the absence of RNG unit 136 in microprocessor 100 viaRNG present bit 302 and choose to obtain random numbers by another,perhaps lower performance, source if the RNG unit 136 is not present.

RNG unit 136 also includes two random bit generators, denoted random bitgenerator 0 206 and random bit generator 1 208, coupled to control logic244. Each of the random bit generators 206 and 208 generate a stream ofrandom bits that are accumulated by RNG unit 136 into bytes of randomdata. Each of the random bit generators 206 and 208 receive a powercntr1 signal 231 that specifies whether to power down the random bitgenerators 206 and 208. In one embodiment, powering down the random bitgenerators 206 and 208 comprises not providing a clock signal to them.The random bit generators 206 and 208 each generate a series of randomdata bits based on random electrical characteristics of microprocessor100, such as thermal noise.

Random bit generator 0 206 receives a DC bias signal 296 from MSR 212.DC bias signal 296 conveys a value stored in DC bias bits 322 of FIG. 3of MSR 212. The DC bias signal 296 value specifies a direct current biasvoltage for partially controlling an operating voltage of free runningring oscillators in random bit generator 0 206.

Random bit generator 0 206 is described in detail in pending U.S. patentapplication Ser. Nos. 10/046,055, 10/046,054, and 10/046,057 entitledAPPARATUS FOR GENERATING RANDOM NUMBERS, OSCILLATOR BIAS VARIATIONMECHANISM, and OSCILLATOR FREQUENCY VARIATION MECHANISM, respectively,(atty dkt# cntr.2113, cntr.2155, cntr.2156) which are herebyincorporated by reference in their entirety.

RNG unit 136 also includes a two-input mux 214 whose inputs are coupledto the outputs of random bit generators 206 and 208. Mux 214 selects oneof the two inputs based on a control signal gen select 252 provided byCSR 226. The gen select signal 252 conveys a value stored in a genselect bit 336 of FIG. 3 in CSR 226.

RNG unit 136 also includes a von Neumann whitener, or compressor, 216coupled to the output of mux 214. Whitener 216 is selectivelyenabled/disabled by a raw bits signal 254 received from MSR 212. The rawbits signal 254 conveys a value stored in raw bits field 324 of FIG. 3of MSR 212. If raw bits signal 254 is true, then whitener 216 simplypasses the bits received from mux 214 through to its output withoutperforming the whitening function. Whitener 216 functions tosignificantly reduce residual bias that may exist in random bitgenerators 206 and 208 by receiving a pair of bits from mux 214 andoutputting either one or none bits according to a predeterminedinput/output function. The input/output function of whitener 216 isdescribed in Table 1 below. TABLE 1 Input Output 00 nothing 01 0 10 1 11nothing

RNG unit 136 also includes an eight-bit shift register 218 coupled towhitener 216. Shift register 218 buffers random data bits received fromwhitener 216, accumulates the random data bits into eight-bit bytes, andoutputs the accumulated random data bytes. Shift register 218 asserts abyte_generated signal 282 to control logic 244 to indicate that it hasaccumulated and output a random data byte 298.

RNG unit 136 also includes a continuous number test (CNT) unit 222coupled to the output of shift register 218. CNT unit 222 receivesrandom bytes 298 from shift register 218 and performs a continuousrandom number generator test on the random bytes 298. CNT unit 222 isselectively enabled/disabled by a CNT enable signal 284 received fromCSR 226. CNT enable signal 284 conveys a value stored in a CNT enablebit 342 of FIG. 3 of CSR 226. If the continuous random number generatortest fails, CNT unit 222 asserts a CNT fail signal 294 provided to CSR226, which is stored in CNT failed bit 344 of FIG. 3 in CSR 226.

In one embodiment, the continuous random number generator test performedby CNT unit 222 substantially conforms to the continuous random numbergenerator test described on page 37 in FIPS 140-2, which is herebyincorporated by reference. In one embodiment, CNT unit 222 performs thetest by employing two eight-byte buffers, referred to as “old” and“new.” After a reset, and after self-test if it is enabled, the firsteight bytes delivered by shift register 218 are accumulated in bufferold. The next eight bytes are accumulated in buffer new. When an XSTOREinstruction is executed, the eight bytes in buffer old are compared withthe eight bytes in buffer new. If the bytes are not equal, then the testpasses and the eight bytes in buffer new are moved to buffer old, andbuffer new is cleared awaiting accumulation of eight more bytes.However, if the bytes are equal, CNT unit 222 asserts the CNT failsignal 294 to signify that the continuous random number generator testfailed.

In one embodiment, XSTORE instructions will return an available bytecount of zero as long as the CNT enable 342 and CNT failed 344 bits ofFIG. 3 are set. In one embodiment, microprocessor 100 stores theavailable byte count and random data bytes to system memory on theparticular XSTORE instruction execution that triggered the continuousrandom number generator test that failed.

In one embodiment, the continuous random number generator test is notperformed across tasks that do not all have the test enabled. That is,the new and old buffers are updated and the continuous random numbergenerator test is performed only for XSTORE instructions executed whenthe CNT enable bit 342 is set. Consequently, a given task is guaranteedto never receive two consecutive eight-byte values that are equal.However, if two tasks are running and one sets the CNT enable bit 342and the other does not, then RNG unit 136 may XSTORE eight bytes to onetask, a task switch occurs, and RNG unit 136 may XSTORE to the othertask eight bytes equal to the previous eight bytes; however, thecontinuous random number generator test will not fail in this case.

RNG unit 136 also includes a string filter 224 coupled to the output ofshift register 218. String filter 224 receives random bytes 298 fromshift register 218 and selectively discards certain of the random bytesas described below, and outputs the non-discarded random bytes. Stringfilter 224 ensures that no contiguous string of like bits, i.e., nocontiguous string of zero bits or contiguous string of one bits, longerthan a specified value is generated by RNG unit 136. The value isspecified by a max_cnt signal 258 received from CSR 226. The max_cntsignal 258 conveys a value specified in string filter max_cnt field 346of FIG. 3 in CSR 226. In one embodiment, the default value of max_cnt346 is 26 bits. In one embodiment, the value of the string filtermax_cnt field 346 must be at least 8. If string filter 224 detects acontiguous string of like bits exceeding max_cnt 258, then string filter224 asserts a filter fail signal 256, which is stored in string filterfail bit 338 of FIG. 3 in CSR 226. String filter 224 is described inmore detail below with respect to FIGS. 10 through 12.

RNG unit 136 also includes a second two-input mux 228. One of the inputsis coupled to the output of string filter 224, and the other input iscoupled to the output of shift register 218. Mux 228 selects one of theinputs based on a filter enable signal 262 provided by CSR 226, whichconveys the value stored in a string filter enable bit 334 of FIG. 3 ofCSR 226.

RNG unit 136 also includes a one-input, two-output demultiplexer 232whose input is coupled to the output of mux 228. A demultiplexer circuitincludes a single data input and a plurality of data outputs. Ademultiplexer also includes a control input. A demultiplexer selects oneof the plurality of data outputs based on the control input and providesthe data received on the data input to the selected output. Demux 232selectively provides a random data byte received on its input to one ofits outputs based on a fill_select signal 264 provided by control logic244.

RNG unit 136 also includes two data buffers, denoted buf0 242 and buf1246, coupled to the outputs of demux 232. Buf0 242 and buf1 246accumulate random data bytes to be stored to system memory by XSTOREinstructions. In one embodiment, buf0 242 and buf1 246 each are capableof storing up to 15 bytes of random data. In one embodiment, buf0 242and buf1 246 each are capable of storing up to 16 bytes of random data.

RNG unit 136 also includes a third two-input mux 236 whose inputs arecoupled to the outputs of buf0 242 and buf1 246. Mux 236 selects one ofthe sets of random data bytes on its inputs based on a store_selectsignal 266 provided by control logic 244 to output on a data bus 278.

RNG unit 136 also includes a TSPO flag register 274 coupled to controllogic 244. TSPO flag register 274 stores a flag indicating whether atask switch by the operating system possibly occurred. Use of TSPO flagregister 274 will be described below in more detail.

RNG unit 136 also includes a second two-output demux 215 coupled tocontrol logic 244. The input of demux 215 is coupled to receive anincrement signal 221 generated by control logic 244. Control logic 244asserts increment signal 221 each time a random data byte is stored intobuf0 242 or buf1 246. Demux 215 selectively provides increment signal221 received on its input to one of its outputs based on fill_selectsignal 264.

RNG unit 136 also includes a third two-input demux 217 coupled tocontrol logic 244. The input of demux 217 is coupled to receive a clearsignal 223 generated by control logic 244. Control logic 244 assertsclear signal 223 each time an XSTORE instruction is executed such thatthe valid random data bytes are removed from buf0 242 or buf1 246. Demux217 selectively provides clear signal 223 received on its input to oneof its outputs based on store_select signal 266.

RNG unit 136 also includes two counters, denoted cntr0 211 and cntr1213, coupled to demux 215 and demux 217. Cntr0 211 and cntr1 213 eachhave an increment, or count, input. The count inputs are coupled to theoutputs of demux 215. Hence, when control logic 244 asserts incrementsignal 221, one of cntr0 211 and cntr1 213 specified by fill_selectsignal 264 is incremented. Cntr0 211 and cntr1 213 also each have aclear input. The clear inputs are coupled to the outputs of demux 217.Hence, when control logic 244 asserts clear signal 223, one of cntr0 211and cntr1 213 specified by store_select signal 266 is cleared to zero.

RNG unit 136 also includes two comparators 225 coupled to the outputs ofcntr0 211 and cntr1 213. Comparators 225 compare the counts output bycntr0 211 and cntr1 213 with the number of bytes cntr0 211 and cntr1 213are capable of storing to determine whether cntr0 211 and cntr1 213 arefull and generate a full0 signal 229 and full1 signal 227 to indicatethe comparison results to control logic 244.

RNG unit 136 also includes a fourth two-input mux 219 whose inputs arecoupled to the output of cntr0 211 and cntr1 213. Mux 219 selects one ofthe counts on its inputs based on store_select signal 266 to output asan available byte count 234. The available byte count 234 is alsoprovided to CSR 226.

RNG unit 136 also includes a register denoted RNG R5 238, or R5 238. R5238 has one input coupled to the output of mux 236 to receive data bytes278. R5 238 has another input coupled to the output of mux 219 toreceive available byte count 234. The output of R5 238 is coupled todata bus 144 of FIG. 1. R5 238 holds the count and data for an XSTOREinstruction. In one embodiment, the count is stored in the leastsignificant byte of R5 238 and the valid data bytes are stored inincreasingly significant byte locations contiguous to the count. In oneembodiment, R5 238 is capable of storing one count byte plus the numberof random data bytes capable of being stored by buf1 242 and buf1 246.

In one embodiment, RNG unit 136 includes four buffers rather than two.Each of the buffers is capable of storing up to eight bytes of randomdata. In this embodiment, demux 215, 217, and 232 comprise four-outputdemuxes; mux 219 and 236 comprise four-input muxes; comparators 225comprise four comparators that generate four full outputs; andfill_select signal 264 and store_select signal 266 comprise two bits forselecting one of the four counters and buffers.

Referring now to FIG. 3, a block diagram illustrating various registersin microprocessor 100 of FIG. 1 related to RNG unit 136 of FIG. 1according to the present invention is shown.

FIG. 3 shows CPUID register 204 of FIG. 2. CPUID register 204 includesan RNG present bit 302. RNG present bit 302 is a read-only feature-flagsbit. If RNG present bit 302 is 1, then RNG unit 136 is present andenabled on microprocessor 100. If RNG present bit 302 is 0, then RNGunit 136 is not present, and the XLOAD and XSTORE instructions areinvalid and if encountered by instruction translator 106 will cause aninvalid instruction exception. Additionally, the bits in MSR 212 areundefined when read and have no effect when written. RNG present bit 302is a copy of RNG present bit 314 of MSR 212.

FIG. 3 also shows MSR 212 of FIG. 2. MSR 212 includes an RNG enable bit312. RNG enable bit 312 is writable. Writing RNG enable bit 312 to a 1enables RNG unit 136. Writing RNG enable bit 312 to a 0 disables RNGunit 136. If RNG enable bit 312 is 0, then the XLOAD and XSTOREinstructions are invalid and if encountered by instruction translator106 will cause an invalid instruction exception. Additionally, the bitsin MSR 212 are undefined when read and have no effect when written. Thevalue of RNG enable bit 312 immediately after reset is 0.

MSR 212 also includes a read-only RNG present bit 314. RNG present bit314 indicates whether RNG unit 136 exists on microprocessor 100. If RNGpresent bit 314 is 0, then RNG unit 136 cannot be enabled by setting RNGenable bit 312, and the bits in MSR 212 are undefined when read and haveno effect when written. Additionally, RNG present bit 314 is cleared ifthe RNG unit 136 self-test fails, as described above with respect toFIG. 2.

MSR 212 also includes a read-only statistical self-test enabled bit 316.Self-test enabled bit 316 indicates whether the reset self-testdescribed above with respect to FIG. 2 is currently enabled. Ifself-test enabled bit 316 is 0, then no self-test is performed afterreset. If self-test enabled bit 316 is 1, then a self-test is performedafter reset. In one embodiment, a self-test is performed after a warmreset as well as a power-up reset of microprocessor 100.

MSR 212 also includes a read-only statistical self-test failed bit 318.Self-test failed bit 318 indicates whether the last reset self-testdescribed above with respect to FIG. 2 failed or not. In one embodiment,if self-test failed bit 318 is 1, then RNG unit 136 cannot be enabled.

MSR 212 also includes writable DC bias bits 322. In one embodiment, DCbias bits 322 comprise three bits. DC bias bits 322 control the DC biassupplied to random bit generator 0 206, which affects the speed andpossible randomness of random bit generator 0 206. In one embodiment, ifthe statistical self-test is performed at reset, then the self-test unit202 determines a correct or best value for DC bias bits 322 and setsthem to the value. The value of DC bias bits 322 immediately after areset is 000.

MSR 212 also includes writable raw bits bit 324. If the raw bits bit 324is set to 0, then whitener 216 of FIG. 2 performs its whitening functiondescribed above with respect to FIG. 2 and delivers whitened bits toshift register 218. If the raw bits bit 324 is set to 1, then whitener216 does not perform its whitening function and instead delivers the rawbits from mux 214 to shift register 218. The value of the raw bits bit324 immediately after a reset is 0.

FIG. 3 also shows CSR 226 of FIG. 2. In one embodiment, CSR 226 is a128-bit register. CSR 226 includes a read-only available byte countfield 332. The available byte count field 332 specifies how many bytesof random data are currently available in buf0 242 or buf1 246 asselected by store_select signal 266 for storing via an XSTOREinstruction. Software can read the available byte count field 332, ifdesired, in order to determine the number of random data bytes currentlyavailable for storing via an XSTORE instruction. Because RNG unit 136synchronously accumulates bytes into buf0 242 and buf1 246, the actualnumber of bytes available to be stored by an XSTORE may be greater atthe time the XSTORE is executed than the available byte count 332previously read by an XLOAD. The value of the available byte count field332 immediately after RNG unit 136 is enabled is 0.

CSR 226 also includes a writable string filter enable bit 334. If stringfilter enable bit 334 is 1, then string filter 224 is enabled; otherwisestring filter 224 is disabled. The operation of string filter 224 isdescribed below in more detail with respect to FIGS. 10 through 12. Thevalue of the string filter enable bit 334 immediately after RNG unit 136is enabled is 0.

CSR 226 also includes a writable gen select bit 336. If gen select bit336 is set to 0, then random bit generator 0 206 is selected via mux 214of FIG. 2 to provide the random bit stream for accumulation; otherwise,random bit generator 1 208 is selected. The value of the gen select bit336 immediately after RNG unit 136 is enabled is 0.

CSR 226 also includes a string filter fail bit 338. String filter failbit 338 is set to 1 to indicate that string filter 224 detected acontiguous string of like bits longer than a value specified in stringfilter max_cnt field 346 as described above with respect to FIGS. 2, and10 through 12. Only RNG unit 136 can set the string filter fail bit 338to 1. However, software may clear string filter fail bit 338 by writinga 0 to it. In one embodiment, filter fail bit 338 is set to 1 by a pulseon filter fail signal 256 and remains set to 1 until software clears it.The value of the string filter fail bit 338 immediately after RNG unit136 is enabled is 0.

CSR 226 also includes a writable CNT enable bit 342. If the CNT enablebit 342 is 1, then CNT unit 222 performs its continuous random numbergenerator tests as described above with respect to FIG. 2. The value ofthe CNT enable bit 342 immediately after RNG unit 136 is enabled is 0.

CSR 226 also includes a read-only CNT failed bit 344. RNG unit 136 setsCNT failed bit 344 to 1 if the CNT enable bit 342 is 1 and thecontinuous random number generator tests fail. In one embodiment, anXSTORE instruction executed while both the CNT enable bit 342 and theCNT failed bit 344 are 1 results in the XSTORE storing an available bytecount of 0 and no data bytes to system memory. Hence, if a task sets theCNT enable bit 342 and a failure occurs while the task is executing, RNGunit 136 is effectively disabled for the task. However, RNG unit 136 isnot disabled for other tasks not setting the CNT enable bit 342. Thevalue of the CNT failed bit 344 immediately after RNG unit 136 isenabled is 0.

CSR 226 also includes a writable string filter max_cnt field 346.Software writes the string filter max_cnt field 346 to specify themaximum number of allowable contiguous like bits tolerable, as describedwith respect to FIGS. 10 through 12 below. In one embodiment, the stringfilter max_cnt field 346 comprises 5 bits. In one embodiment, thedefault value of string filter max_cnt field 346 is 26.

In one embodiment, various ones of the fields of MSR 212 are included inCSR 226 rather than MSR 212. Hence, the values in MSR 212 are saved andrestored with CSR 226 to accommodate multitasking operation as describedherein, and particularly with respect to FIGS. 4 through 9.

FIG. 3 also shows RNG R5 register 238 of FIG. 2. R5 238 comprises twofields: an available byte count field 362 and another field 364 forstoring random data bytes, as described above. In one embodiment, thevalid random data bytes are right adjusted next to the available bytecount field 362.

FIG. 3 also shows SSE registers 352. SSE registers 352 comprise eight128-bit registers denoted XMM0 through XMM7. XMM0 is designated XMM0372, XMM3 is designated 376, and XMM5 is designated XMM5 374 in FIG. 3.In one embodiment, SSE registers 352 are substantially similar to SSEregisters comprised in a Pentium III or IV as described on page 10-4 ofIA-32® Intel Architecture Software Developer's Manual, Volume 1: BasicArchitecture, 2002, which is hereby incorporated by reference. RNG CSR226 shadows XMM0 372 and RNG R5 238 shadows XMM5 374 as described below.

In one embodiment, microprocessor 100 includes various fuses that may betemporarily or permanently set during the manufacturing process ofmicroprocessor 100 to select values of various bits in the CSR 226 andMSR 212 at reset time in order to override the reset values describedabove.

Referring now to FIG. 4, a flowchart illustrating operation ofmicroprocessor 100 of FIG. 1 when executing an instruction that loads avalue into XMM0 register 372 of FIG. 3 according to the presentinvention is shown. An instruction that loads XMM0 372 is an instructionexecuted by the microprocessor that loads the XMM0 register 372 with avalue from system memory, such as a MOVAPS instruction. The MOVAPSinstruction moves data from system memory to a specified XMM register,or vice versa, and is described on pages 3-443 through 3-444 of theIA-32® Intel Architecture Software Developer's Manual, Volume 2:Instruction Set Reference, 2001, which are hereby incorporated byreference. Examples of other instructions that load XMM0 372 from systemmemory are MOVAPD and MOVDQA. Because XMM0 372 is a register saved tomemory and restored from memory by the operating system on a taskswitch, when a task switch occurs the operating system will execute aninstruction such as a MOVAPS instruction to restore the switched-totask's previous value of XMM0 372 from memory. Flow begins at block 402.

At block 402, microprocessor 100 executes an instruction such as theMOVAPS instruction by fetching the value from the location in systemmemory specified by the instruction and loads the value into XMM0 372.Hence, any time XMM0 372 is loaded from memory, it is possible that atask switch has occurred. Flow proceeds to block 404.

At block 404, instruction translator 106 notifies RNG unit 136 that aMOVAPS instruction, or similar instruction that loads XMM0 372 frommemory, has been translated. Once the value has been loaded into XMM0372, control logic 244 of RNG unit 136 sets the TSPO flag 274 toindicate that a task switch possibly occurred. Flow ends at block 404.

Referring now to FIG. 5, a block diagram illustrating operation ofmicroprocessor 100 of FIG. 1 when executing an XLOAD instructionaccording to the present invention is shown. The XLOAD instruction isthe means by which software loads a value into the CSR 226 of FIG. 2 tospecify the control values under which RNG unit 136 will operate. A newinstruction beyond the Pentium III or IV instruction set is required toload CSR 226 since CSR 226 does not exist in a Pentium III or IV.Advantageously, the XLOAD instruction also loads the control values intoXMM0 372 to facilitate multitasking operation with RNG unit 136 asdescribed herein.

FIG. 5 shows the format of an XLOAD instruction specifying XMM0 372,which is:

-   -   XLOAD XMM0, memaddr        where memaddr specifies a memory address in system memory 502.        The XLOAD instruction operates like the MOVAPS instruction        except that CSR 226 is also loaded with the value from memory in        addition to XMM0 372. In one embodiment, XLOAD moves 16 bytes of        data 504 from memaddr into CSR 226 and also into XMM0 372, as        shown. In one embodiment, the opcode value for the XLOAD        instruction is 0x0F 0x5A followed by the standard mod R/M        register and address format bytes specified by x86 instructions.        In another embodiment, the opcode value for the XLOAD        instruction is 0x0F 0xA6 0xC0. If an XLOAD instruction specifies        one of the SSE registers 352 other than XMM0 372, then the        specified SSE register 352 is loaded; however, CSR 226 is not        loaded.

Referring now to FIG. 6, a flowchart illustrating operation ofmicroprocessor 100 of FIG. 1 when executing an XLOAD instruction to XMM0register 372 of FIG. 3 according to the present invention is shown. Flowbegins at block 602.

At block 602, microprocessor 100 loads CSR 226 of FIG. 2 and XMM0 372 ofFIG. 3 with the value in system memory 502 at the memory addressspecified by the XLOAD instruction as shown in FIG. 5. Flow proceeds toblock 604.

At block 604, RNG unit 136 discards the contents of buf0 242 and buf1246 in response to the loading of CSR 226 since the random data bytesaccumulated in buf0 242 and buf1 246 may not have been generated withthe control values in CSR 226 required by the new task that is nowloading CSR 226. Flow proceeds to block 606.

At block 606, RNG unit 136 clears the available byte count to 0 in cntr0211 and cntr1 213 since the random data bytes in buf0 242 and buf1 246were discarded at block 604. Flow proceeds to block 608.

At block 608, RNG unit 136 restarts the random number accumulation. Thatis, the random bit generator 206 or 208 selected by gen select signal252 generates random bits based on DC bias signal 296 in the case ofrandom bit generator 0 206; whitener 216 selectively whitens the bitsbased on the raw bits signal 254; CNT unit 222 selectively performscontinuous random number generator tests based on CNT enable signal 284;string filter 224 selectively filters the bytes accumulated by shiftregister 218 based on filter enable signal 262 and max_cnt signal 258;buf0 242 and buf0 246 accumulate the random data bytes based onfill_select signal 264; and cntr0 211 and cntr1 213 count the bytesaccumulated in buf0 242 and buf1 246 based on fill_select signal 264.Flow proceeds to block 612.

At block 612, control logic 244 clears TSPO flag 274 since CSR 226 hasbeen updated to the control values desired by the current task. Flowends at block 612.

Referring now to FIG. 7, a block diagram illustrating operation ofmicroprocessor 100 of FIG. 1 when executing an XSTORE instructionaccording to the present invention is shown. The XSTORE instruction isthe means by which software stores the count of available random databytes and the random data bytes themselves from R5 238 to system memory.A new instruction beyond the Pentium III or IV instruction set isrequired to store RNG R5 238 since it does not exist in a Pentium III orIV. Advantageously, the XSTORE instruction atomically writes the countand data bytes to memory to facilitate multitasking operation with RNGunit 136 as described herein. That is, the XSTORE instruction is notinterruptible. Hence, when a task executes an XSTORE instruction,another task may not interrupt the XSTORE instruction to modify theavailable byte count or random data bytes that will be written to systemmemory by the XSTORE instruction. Hence, the XSTORE instructionadvantageously inherently facilitates multitasking with respect tosupplying a variable number of random data bytes by atomically writingboth the data and count.

FIG. 7 shows the format of an XSTORE instruction, which is:

-   -   XSTORE memaddr, XMM5        Memaddr specifies a memory address in system memory 502. The        XSTORE instruction operates like the MOVAPS instruction except        that the specified XMM register is not stored to system memory;        instead R5 238 is stored to system memory if XMM5 374 is        specified. That is, R5 238 shadows XMM5 374. XSTORE moves the        count specifying the available valid random data bytes 362 of        FIG. 3 from R5 238 to a location 702 at memaddr in system memory        502, as shown. Additionally, XSTORE moves the valid random bytes        of data 364 specified by the count 362 to a location 704 in        system memory 502 immediately adjacent to the available byte        count 702, as shown.

In one embodiment, the opcode value for the XSTORE instruction is 0x0F0x5B followed by the standard mod R/M register and address format bytesspecified by x86 instructions. In another embodiment, the opcode valuefor the XSTORE instruction is 0x0F 0xA7 0xC0. In one embodiment, theXSTORE instruction requires that the ES:EDI registers in register file108 specify memaddr, i.e., point to the starting memory address wherethe count and random data bytes are to be stored. In one embodiment, theXSTORE does not allow segment overriding. If an XSTORE instructionspecifies one of the SSE registers 352 other than XMM5 374, then theresults are undefined.

In one embodiment, the number of random data bytes 704 thatmicroprocessor 100 stores to system memory equals the available bytecount 702 also written to system memory.

In another embodiment, the number of random data bytes 704 thatmicroprocessor 100 stores to system memory is equal to one less than thesize in bytes of RNG R5 238. That is, if RNG R5 238 is a 16-byteregister capable of holding up to 15 random data bytes 364 and one byteof available byte count 362, then microprocessor 100 stores 16 bytes tosystem memory 502: 15 bytes of random data to the random data bytes 704location and one count byte to the available byte count 702 location insystem memory 502. However, some of the 15 bytes written to systemmemory 502 may not be valid. In one embodiment, the number of byteswritten to memory is always a power of 2. Only the first N bytes arevalid, where N is the available byte count 702.

In this embodiment, RNG unit 136 clears the buffer, i.e., buf0 242 orbuf1 246 of FIG. 2, implicated by an XSTORE operation. By clearing thebuffer, microprocessor 100 improves security by avoiding the problem oftasks being able to view one another's random data. For example, assumea first task performs a first XSTORE that stores 15 bytes of random datafrom buff 242 to system memory and a second XSTORE that stores 15 bytesof random data from buf1 246 to system memory; then the operating systemswitches to a second task which immediately executes an XSTORE beforeRNG unit 136 has accumulated any more bytes of random data into buf0242. If the RNG unit 136 did not clear buf0 242 after the first XSTORE,then the random data received by the first task would also be stored tothe second task's memory location, thereby enabling the second task toview the first task's random data.

In one embodiment, the XSTORE instruction specifies a maximum number ofrandom data bytes to store to system memory. In one embodiment, themaximum number of bytes is specified in one of the general-purposeregisters of register file 108, such as ECX. In this embodiment, if morebytes are available in buf0 242 or buf1 246 selected by store_select 266than the maximum number specified in ECX, then microprocessor 100 onlystores the maximum number of bytes specified in ECX; otherwise, theXSTORE instruction stores the number of valid bytes available. In eithercase, the XSTORE instruction stores into the available byte countlocation 702 the number of valid random data bytes stored to the databyte location 704 in system memory 502.

In one embodiment, the XSTORE instruction specifies a required number ofrandom data bytes to store to system memory. In this embodiment, therequired number of bytes is specified in one of the general-purposeregisters of register file 108, such as ECX. In this embodiment, theXSTORE instruction is prefixed with an x86 REP prefix. In thisembodiment, the REP XSTORE instruction is not atomic. That is, the REPXSTORE is interruptible since the number of random bytes required may belarge. However, since the number of random data bytes stored is notvariable, i.e., the software knows the number of random data bytes thatare to be stored to memory, it is not necessary that the instruction beatomic.

Referring now to FIG. 8, a flowchart illustrating operation ofmicroprocessor 100 of FIG. 1 when executing an XSTORE instruction fromXMM5 register of FIG. 3 according to the present invention is shown.Flow begins at block 802.

At block 802 interrupt unit 146 of FIG. 1 disables interrupts inresponse to instruction translator 106 of FIG. 1 notifying interruptunit 146 that an XSTORE instruction was translated. Flow proceeds todecision block 804.

At decision block 804, control logic 244 of FIG. 2 examines TSPO flag274 to determine whether the flag is set. If so flow proceeds to block806. Otherwise, flow proceeds to block 816.

At block 806, RNG unit 136 copies the contents of XMM0 372 to CSR 226and clears the TSPO flag 274. Since TSPO flag 274 indicates that a taskswitch may have possibly occurred since the last XSTORE or XLOAD, asindicated by a load from system memory of XMM0 372 according to step 402of FIG. 4, the possibility exists that CSR 226 does not have the correctcontrol values for the task currently executing the XSTORE instruction.Hence, the XSTORE instruction must update the CSR 226 with the correctcontrol values. The correct values are stored in XMM0 372, since thecorrect control values were originally loaded into XMM0 372 and alsointo CSR 226 by an XLOAD executed when the task initialized and wererestored to XMM0 372 by the operating system when it switched back tothe current task. Flow proceeds to block 808.

At block 808, RNG unit 136 discards the contents of buf0 242 and buf1246 in response to the loading of CSR 226 since the random data bytesaccumulated in buf0 242 and buf1 246 may not have been generated withthe control values in CSR 226 required by the new task for which newcontrol values were copied into CSR 226 in block 806. Flow proceeds toblock 812.

At block 812, RNG unit 136 clears the available byte count to 0 in cntr0211 and cntr1 213 since the random data bytes in buf0 242 and buf1 246were discarded at block 808. Flow proceeds to block 814.

At block 814, RNG unit 136 restarts the random number accumulation, asdescribed above with respect to block 608 of FIG. 6. Flow proceeds toblock 816.

At block 816, RNG unit 136 atomically stores R5 238 to system memory 502at the memory address specified by the XSTORE instruction, which holdsthe value of cntr0 211 or cntr1 213 specified by store_select signal 266along with the valid random data bytes from buf0 242 or buf1 246specified by store_select signal 266, as shown in FIG. 7. Flow proceedsto block 818.

At block 818, control logic 244 asserts clear signal 223 to clear cntr0211 or cntr1 213 specified by store_select signal 266 since the validrandom data bytes have been consumed by the store to memory at block816. Flow proceeds to block 822.

At block 822, control logic 244 updates store_select signal 266. Thatis, if store_select signal 266 was 0, then control logic 244 updatesstore_select signal 266 to 1. Conversely, if store_select signal 266 was1, then control logic 244 updates store_select signal 266 to 0. Flowproceeds to block 824.

At block 824, interrupt unit 146 enables interrupts since the XSTOREinstruction has completed execution. Flow ends at block 824.

Referring now to FIG. 9, a flowchart illustrating an example ofmulti-tasking operation of microprocessor 100 of FIG. 1 with respect torandom number generation according to the present invention is shown.The flowchart of FIG. 9 illustrates a typical scenario in which twotasks each initialize RNG unit 136 and execute XSTORE instructions tostore random data bytes to memory. FIG. 9 illustrates how the presentinvention advantageously supports multitasking between the two tasks,task A and task B, even though the operating system does not includesupport for saving and restoring the state of RNG unit 136, namely CSR226. Flow begins at block 902.

At block 902, a reset occurs, which causes control logic 244 to clearTSPO flag 274. Flow proceeds to block 904.

At block 904, the operating system starts up task A, and task A'sinitialization code executes an XLOAD instruction to XMM0 372 toinitialize CSR 226 and XMM0 372 with the desired control values denotedvalue A. Flow proceeds to block 906.

At block 906, RNG unit 136 discards the contents of buf0 242 and buf1246, clears cntr0 211 and cntr1 213, restarts random number generationand accumulation, and clears TSPO flag 274 in response to the XLOAD,according to blocks 604, 606, 608, and 612 of FIG. 6. Flow proceeds toblock 908.

At block 908, task A executes an XSTORE instruction to store random datagenerated based on control value A loaded into CSR 226 at block 904.Flow proceeds to block 912.

At block 912, to execute the XSTORE of the previous block, RNG unit 136atomically stores the count and data to system memory accumulated sincethe restart at block 906, as shown in FIG. 7 and described in FIG. 8.Flow proceeds to block 914.

At block 914, the operating system performs a task switch from task A totask B. Among other things, the operating system stores the value ofXMM0 372, which contains control value A, to system memory to save thestate of task A. However, the operating system does not store CSR 226 tomemory to save its state because the operating system does not knowabout CSR 226. Flow proceeds to block 916.

At block 916, RNG unit 136 sets TSPO flag 274 in response to the load ofXMM0 372 at block 914, according to step 404 of FIG. 4. Flow proceeds toblock 918.

At block 918, the operating system starts up task B, and task B'sinitialization code executes an XLOAD instruction to XMM0 372 toinitialize CSR 226 and XMM0 372 with the desired control values denotedvalue B. Flow proceeds to block 922.

At block 922, RNG unit 136 discards the contents of buf0 242 and buf0246, clears cntr0 211 and cntr1 213, restarts random number generationand accumulation, and clears TSPO flag 274 in response to the XLOAD,according to blocks 604, 606, 608, 612 of FIG. 6. Flow proceeds to block924.

At block 924, task B executes an XSTORE instruction to store random datagenerated based on control value B loaded into CSR 226 at block 918.Flow proceeds to block 924.

At block 926, to execute the XSTORE of the previous block, RNG unit 136atomically stores the count and data to system memory accumulated sincethe restart at block 922, as shown in FIG. 7 and described in FIG. 8.Flow proceeds to block 928.

At block 928, the operating system performs a task switch from task B totask A. Among other things, the operating system stores the value ofXMM0 372, which contains control value B, to system memory to save thestate of task B. However, the operating system does not store CSR 226 tomemory to save its state because the operating system does not knowabout CSR 226. Additionally, the operating system restores the state oftask A, which includes loading into XMM0 372 value A from system memorypreviously saved at block 914. Flow proceeds to block 932.

At block 932, RNG unit 136 sets TSPO flag 274 in response to the load ofXMM0 372 at block 928, according to step 404 of FIG. 4. Flow proceeds toblock 934.

At block 934, task A executes an XSTORE instruction to store random datagenerated based on control value A loaded into CSR 226 at block 904.However, value A was overwritten in CSR 226 at block 918. Hence, therandom data bytes currently accumulated in buf0 242 and buf1 246 werenot generated based on value A, but instead were generated based onvalue B. Flow proceeds to block 936.

At block 936, RNG unit 136 determines that TSPO flag 274 is setaccording to block 804 of FIG. 8, and consequently copies the contentsof XMM0 372 to CSR 226, thereby restoring value A to CSR 226, accordingto block 806 of FIG. 8. In addition, RNG unit 136 clears TSPO flag 274,according to block 806, since CSR 226 has been restored. Flow proceedsto block 938.

At block 938, RNG unit 136 discards the contents of buf0 242 and buf1246, clears cntr0 211 and cntr1 213, and restarts random numbergeneration and accumulation, in response to the copy into CSR 226 atblock 936, according to blocks 808, 812, and 814 of FIG. 8. Flowproceeds to block 942.

At block 942, to execute the XSTORE of block 934, RNG unit 136atomically stores the count and data to system memory accumulated sincethe restart at the previous block, as shown in FIG. 7 and described inFIG. 8. In this case, the count is 0 and no valid random data bytes arestored to system memory since cntr0 211 and cntr1 213 were cleared andthe contents of buf0 242 and buf1 246 were discarded at the previousblock. Flow proceeds to block 944.

At block 944, task A executes an XSTORE instruction to store random datagenerated based on control value A loaded into CSR 226 at block 904,which was restored to value A at block 936. Flow proceeds to block 946.

At block 946, to execute the XSTORE of the previous block, RNG unit 136atomically stores the count and data to system memory accumulated sincethe restart at block 938, as shown in FIG. 7 and described in FIG. 8.Flow proceeds to block 948.

At block 948, task A executes an XSTORE instruction to store random datagenerated based on control value A loaded into CSR 226 at block 904,which was restored to value A at block 936. Flow proceeds to block 952.

At block 952, to execute the XSTORE of the previous block, RNG unit 136atomically stores the count and data to system memory accumulated sincethe restart at block 938, less the bytes stored by the last XSTORE,which was at block 946, as shown in FIG. 7 and described in FIG. 8. Flowends at block 952.

Referring now to FIG. 10, a block diagram illustrating string filter 224of RNG unit 136 of FIG. 2 of microprocessor 100 of FIG. 1 according tothe present invention is shown.

For the purposes of the present disclosure, leading one bits are definedas the contiguous one bits at the beginning of a byte. A byte maycontain between zero and eight, inclusive, leading one bits. Forexample, the byte 00011111 has five leading one bits; the byte 11111110has zero leading one bits; and the byte 11111111 has eight leading onebits.

For the purposes of the present disclosure, leading zero bits aredefined as the contiguous zero bits at the beginning of a byte. A bytemay contain between zero and eight, inclusive, leading zero bits. Forexample, the byte 11100000 has five leading zero bits; the byte 00000001has zero leading zero bits; and the byte 00000000 has eight leading zerobits.

For the purposes of the present disclosure, trailing one bits aredefined as the contiguous one bits at the end of a byte; however a bytethat is all ones is defined as having no trailing one bits. A byte maycontain between zero and seven, inclusive, trailing one bits. Forexample, the byte 11110000 has four trailing one bits; the byte 11111110has seven trailing one bits; the byte 01111111 has zero trailing onebits; and the byte 11111111 has zero trailing one bits.

For the purposes of the present disclosure, trailing zero bits aredefined as the contiguous zero bits at the end of a byte; however a bytethat is all zeros is defined as having no trailing zero bits. A byte maycontain between zero and seven, inclusive, trailing zero bits. Forexample, the byte 00001111 has four trailing zero bits; the byte00000001 has seven trailing zero bits; the byte 10000000 has zerotrailing zero bits; and the byte 0000000 has zero trailing zero bits.

String filter 224 includes compare logic 1002. Compare logic 1002receives random data byte 298 from shift register 218 of FIG. 2. Comparelogic 1002 examines the bits in the random data byte 298 and generatesvarious signals used to detect contiguous strings of ones and zeros asnow described.

Compare logic 1002 generates a num leading_ones signal 1022A thatspecifies the number of leading one bits in random data byte 298.

Compare logic 1002 generates a num trailing_ones signal 1028A thatspecifies the number of trailing one bits in random data byte 298.

Compare logic 1002 also generates an all_ones signal 1048A that is trueif random data byte 298 contains all one bits.

Compare logic 1002 also generates a leading_ones signal 1036A that istrue if random data byte 298 contains leading one bits.

Compare logic 1002 also generates a trailing_ones signal 1038A that istrue if random data byte 298 contains trailing one bits.

String filter 224 also includes a first counter 1016A for storing thecurrent count of contiguous one bits. In one embodiment, counter 1016Acomprises a six-bit register. The output of counter 1016A is a ones_cntsignal 1024A.

String filter 224 also includes a first adder 1012A that addsnum_leading_ones 1022A and ones_cnt signal 1024A to produce anew_ones_cnt signal 1026A.

String filter also includes a first four-input mux 1014A. Mux 1014Areceives on its inputs ones_cnt signal 1024A, new_ones_cnt signal 1026A,num_trailing_ones signal 1028A, and a hard-coded value of zero 1032A.Mux 1014A selects one of the inputs for outputting to counter 1016Abased on a one_select signal 1042A.

Compare logic 1002 generates a num_leading_zeros signal 1022B thatspecifies the number of leading zero bits in random data byte 298.

Compare logic 1002 generates a num_trailing_zeros signal 1028B thatspecifies the number of trailing zero bits in random data byte 298.

Compare logic 1002 also generates an all_zeros signal 1048B that is trueif random data byte 298 contains all zero bits.

Compare logic 1002 also generates a leading_zeros signal 1036B that istrue if random data byte 298 contains leading zero bits.

Compare logic 1002 also generates a trailing_zeros signal 1038B that istrue if random data byte 298 contains trailing zero bits.

String filter 224 also includes a second counter 1016B for storing thecurrent count of contiguous zero bits. In one embodiment, counter 1016Bcomprises a six-bit register. The output of counter 1016B is a zeros_cntsignal 1024B.

String filter 224 also includes a second adder 1012B that addsnum_leading_zeros 1022B and zeros_cnt signal 1024B to produce anew_zeros_cnt signal 1026B.

String filter also includes a second four-input mux 1014B. Mux 1014Breceives on its inputs zeros_cnt signal 1024B, new_zeros_cnt signal1026B, num_trailing_zeros signal 1028B, and a hard-coded value of zero1032B. Mux 1014B selects one of the inputs for outputting to counter1016B based on a zero_select signal 1042B.

String filter 224 also includes a first comparator 1046A that comparesnew_ones_cnt signal 1026A with max_cnt signal 258 of FIG. 2. Ifnew_ones_cnt signal 1026A is greater than max_cnt signal 258, thencomparator 1046A generates a true value on ones_exceeded signal 1034A;otherwise, comparator 1046A generates a false value on ones_exceededsignal 1034A.

String filter 224 also includes a second comparator 1046B that comparesnew_zeros_cnt signal 1026B with max_cnt signal 258 of FIG. 2. Ifnew_zeros_cnt signal 1026B is greater than max_cnt signal 258, thencomparator 1046B generates a true value on zeros_exceeded signal 1034B;otherwise, comparator 1046B generates a false value on zeros_exceededsignal 1034B.

String filter 224 also includes a two-input OR gate 1004 whose inputsare coupled to the outputs of comparator 1046A and comparator 1046B. ORgate 1004 receives ones_exceeded signal 1034A and zeros_exceeded signal1034B on its inputs. OR gate 1004 generates a max_cnt_exceeded signal1044, which is provided as an input to select logic 1006.

String filter 224 also includes a two-input AND gate 1008 coupled to ORgate 1004. AND gate 1008 receives max_cnt_exceeded signal 1044 from ORgate 1004 on one input and filter enable signal 262 of FIG. 2 on itsother input. The output of AND gate 1008 is filter fail signal 256 ofFIG. 2.

String filter 224 also includes select logic 1006 coupled to receiveall_ones signal 1048A, leading_ones signal 1036A, trailing_ones signal1038A, max_cnt_exceeded signal 1044, leading_zeros signal 1036B,trailing_zeros signal 1038B, and all_zeros signal 1048B. Select logic1006 generates one_select signal 1042A and zero_select signal 1042Baccording to the following code. retain_counts = max_cnt_exceeded &filter enable; increment_zeros = all_zeros & (! retain_counts);load_zeros = trailing_zeros & (! retain_counts) & (! increment_zeros);clear_zeros = (! retain_counts) & (! increment_zeros) & (! load_zeros);increment_ones = all_ones & (! retain_counts); load_ones = trailing_ones& (! retain_counts) & (! increment_ones); clear_ones = (! retain_counts)& (! increment_ones) & (! load_ones); if (retain_counts) {   zero_select = 3; // select zeros_cnt input } else if(increment_zeros) {    zero_select = 2; // select new_zeros_cnt input }else if (load_zeros) {    zero_select = 1; // select num_trailing_zerosinput }  else if (clear_zeros) {    zero_select = 0; // selecthard-coded 0 input } if (retain_counts) {    one_select = 3; // selectones_cnt input } else if (increment_ones) {    one_select = 2; // selectnew_ones_cnt input } else if (load_ones) {    one_select = 1; // selectnum_trailing_ones input } else if (clear_ones) {    one_select = 0; //select hard-coded 0 input }

Referring now to FIG. 11, a flowchart illustrating operation of stringfilter 224 of FIG. 10 according to the present invention is shown. Flowbegins at block 1102.

At block 1102, counters 1016A and 1016B are initialized to a zero value.Flow proceeds to block 1104.

At block 1104, RNG unit 136 of FIG. 1 generates a byte of random data onrandom byte signal 298 of FIG. 2 and compare logic 1002 generates itssignals based on examination of random data byte 298. Flow proceeds toblock 1106.

At block 1106, adder 1012A adds num_leading_ones 1022A and ones_cnt1024A to produce new_ones_cnt 1026A and adder 1012B addsnum_leading_zeros 1022B and zeros_cnt 1024B to produce new_zeros_cnt1026B. Flow proceeds to decision block 1112.

At block 1112, select logic 1006 examines max_cnt_exceeded 1044 todetermine whether the number of contiguous zeros or ones has exceededmax_cnt 298. If so, flow proceeds to decisions block 1114. Otherwise,flow proceeds to decision block 1124.

At decision block 1114, AND gate 1008 examines filter enable 262 signalto determine whether string filter 224 is enabled. If so, AND gate 1008generates a true value on filter fail signal 256 of FIG. 2. Flowproceeds to block 1118.

At block 1118, in response to filter fail signal 256 being true, controllogic 244 does not assert the increment signal 221 of FIG. 2 and doesnot cause random byte 298 to be loaded into buf0 242 or buf1 246, eventhough shift register 218 has generated a true value on byte_generatedsignal 282. Thus, RNG unit 136 discards random byte 298 since randombyte 298 has caused the number of contiguous ones or zeros to exceedmax_cnt 258. Flow proceeds to block 1122.

At block 1122, select logic 1006 generates a value of 3 on one_selectsignal 1042A and on zero_select signal 1042B in order to cause muxes1014A and 1014B, respectively, to retain the current ones_cnt 1024A andzeros_cnt 1024B, respectively. Flow returns to block 1104.

At decision block 1124, select logic 1006 examines all_zeros signal1048B to determine whether random data byte 298 contains all zeros. Ifso, flow proceeds to block 1126. Otherwise, flow proceeds to decisionblock 1128.

At block 1126, select logic 1006 generates a value of 2 on zero_selectsignal 1042B to cause mux 1014B to select new_zeros_cnt 1026B andgenerates a value of 0 on one_select signal 1042A to cause mux 1014A toselect hard-coded 0 input 1032A. Flow proceeds to block 1148.

At decision block 1128, select logic 1006 examines trailing_zeros signal1038B to determine whether random data byte 298 contains any trailingzeros. If so, flow proceeds to block 1132. Otherwise, flow proceeds toblock 1134.

At block 1132, select logic 1006 generates a value of 1 on zero_selectsignal 1042B to cause mux 1014B to select num_trailing_zeros 1028B andgenerates a value of 0 on one_select signal 1042A to cause mux 1014A toselect hard-coded 0 input 1032A. Flow proceeds to block 1148.

At block 1134, select logic 1006 generates a value of 0 on zero_selectsignal 1042B to cause mux 1014B to select hard-coded 0 input 1032B. Flowproceeds to decision block 1136.

At decision block 1136, select logic 1006 examines all_ones signal 1048Ato determine whether random data byte 298 contains all ones. If so, flowproceeds to block 1138. Otherwise, flow proceeds to decision block 1142.

At block 1138, select logic 1006 generates a value of 2 on one_selectsignal 1042A to cause mux 1014A to select new_ones_cnt 1026A. Flowproceeds to block 1148.

At decision block 1142, select logic 1006 examines trailing_ones signal1038A to determine whether random data byte 298 contains anytrailing_ones. If so, flow proceeds to block 1144. Otherwise, flowproceeds to block 1146.

At block 1144, select logic 1006 generates a value of 1 on one_selectsignal 1042A to cause mux 1014A to select num_trailing_ones 1028A. Flowproceeds to block 1148.

At block 1146, select logic 1006 generates a value of 0 on one_selectsignal 1042A to cause mux 1014A to select hard-coded 0 input 1032A. Flowproceeds to block 1148.

At block 1148, control logic 244 causes random data byte 298 to beloaded into buf0 242 or buf1 246 selected by fill_select signal 264 andasserts increment signal 221 to increment cntr0 211 or cntr1 213selected by fill_select signal 264. Flow returns to block 1104.

Referring now to FIG. 12, a block diagram illustrating operation ofmicroprocessor 100 of FIG. 1 when executing an XSTORE instructionaccording to an alternate embodiment of the present invention is shown.The XSTORE instruction of FIG. 12 is similar to the XSTORE instructionof FIG. 7, however in the alternate embodiment, the count of validrandom data bytes is loaded into one of the general purpose registers inregister file 108, such as the EAX 1202 register, rather than beingstored to system memory. Advantageously, like the XSTORE instruction ofFIG. 7, the XSTORE instruction of FIG. 12 atomically loads the countinto EAX along with storing the random data bytes to memory tofacilitate multitasking operation with RNG unit 136. That is, the XSTOREinstruction of FIG. 12 is also not interruptible.

Referring now to FIG. 13, a flowchart illustrating multi-bufferingoperation of RNG unit 136 of FIG. 2 according to the present inventionis shown. Flow begins at block 1302.

At block 1302, reset signal 248 is asserted. Flow proceeds to block1304.

At block 1304, control logic 244 of FIG. 2 initializes fill_selectsignal 264 and store_select signal 266 to 0, and clears cntr0 211 andcntr1 213 in response to the reset at block 1302. Flow proceeds todecision block 1306.

At decision block 1306, control logic 244 determines whether an XSTOREinstruction is being executed by examining xstore signal 268. If so,flow proceeds to decision block 1308. Otherwise, flow proceeds todecision block 1322.

At decision block 1308, control logic 244 determines whether random bitgenerator 0 206 or random bit generator 1 208 selected by gen selectsignal 252 is powered off. If so, flow proceeds to block 1312.Otherwise, flow proceeds to block 1314.

At block 1312, control logic 244 powers up the selected random bitgenerator via power cntr1 signal 231. Flow proceeds to block 1314.

At block 1314, microprocessor 100 atomically stores to system memory thevalue in cntr0 211 or cntr1 213 selected by store_select signal 266 andthe valid data bytes in buf0 242 or buf1 246 selected by store_selectsignal 266, according to block 816 of FIG. 8 and as shown in FIG. 7.Flow proceeds to block 1316.

At block 1316, control logic 244 asserts clear signal 223 to clear cntr0211 or cntr1 213 selected by store_select signal 266. Flow proceeds toblock 1318.

At block 1318, control logic 244 updates store_select signal 266 toselect the other buffer and counter. In embodiments in which RNG unit136 includes more than two buffers, store_select signal 266 comprisesmore than one bit, and updating store_select signal 266 comprisesincrementing store_select signal 266 and wrapping around back to zerowhen incrementing past the number of buffers. Flow proceeds to decisionblock 1322.

At decision block 1322, control logic 244 determines whether a goodrandom data byte was generated by examining byte_generated signal 282 tosee if it is true and examining filter fail signal 256 to see if it isfalse. If so, flow proceeds to block 1324. Otherwise, flow returns todecision block 1306.

At block 1324, control logic 244 loads the good random data byte intobuf0 242 or buf1 246 selected by fill_select signal 264 and incrementscntr0 211 or cntr1 213 selected by fill_select signal 264. Flow proceedsto decision block 1326.

At decision block 1326, control logic 244 examines full0 signal 229 orfull1 signal 227 specified by fill_select signal 264 to determinewhether buf0 242 or buf1 246 selected by fill_select signal 264 is full.If so, flow proceeds to block 1328. Otherwise, flow returns to block1306.

At block 1328, control logic 244 updates fill_select signal 264. In oneembodiment in which RNG unit 136 includes two buffers, updatingfill_select signal 264 comprises toggling fill_select signal 264. Inembodiments in which RNG unit 136 includes more than two buffers,fill_select signal 264 comprises more than one bit, and updatingfill_select signal 264 comprises incrementing fill_select signal 264 andwrapping around back to zero when incrementing past the number ofbuffers. Flow proceeds to decision block 1332.

At decision block 1332, control logic 244 examines full0 signal 229 orfull1 signal 227 specified by fill_select signal 264 as updated at block1328 to determine whether buf0 242 or buf1 246 selected by fill_selectsignal 264 is full, i.e., to determine whether all the buffers are full.If so, flow proceeds to block 1334. Otherwise, flow returns to block1306.

At block 1334, control logic 244 powers off random bit generator 0 206and random bit generator 1 208 via power cntr1 signal 231 since all thebuffers are full. Flow returns to decision block 1306.

Referring now to FIG. 14, a flowchart illustrating operation ofmicroprocessor 100 of FIG. 1 when executing an XLOAD instruction of FIG.3 according to an alternate embodiment of the present invention isshown. The flowchart of FIG. 14 is identical to the flowchart of FIG. 6and like numbered blocks are the same, except that FIG. 14 includes anadditional decision block 1403. Flow proceeds from block 602 to decisionblock 1403. At decision block 1403, control logic 244 of FIG. 2determines whether relevant bits in CSR 226 have been changed by theload of CSR 226 at block 602. If so flow proceeds to block 604 as inFIG. 6. Otherwise, flow proceeds to block 612, as shown. The alternateembodiment has the advantage of not unnecessarily discarding alreadyaccumulated random bytes and restarting random byte accumulation. Thatis, if the load of CSR 226 did not change any of the values affectingthe generation of random numbers by RNG unit 136, then there is no needto discard already accumulated random bytes and restart random byteaccumulation since the random bytes were generated using the desiredcontrol values. In one embodiment, the relevant CSR 226 bits are stringfilter enable bit 334, gen select bit 336, CNT enable bit 342, andstring filter max_cnt 346.

Referring now to FIG. 15, a flowchart illustrating operation ofmicroprocessor 100 of FIG. 1 when executing an XSTORE instruction ofFIG. 3 according to an alternate embodiment of the present invention isshown. The flowchart of FIG. 15 is identical to the flowchart of FIG. 8and like numbered blocks are the same, except that FIG. 15 includes anadditional decision block 1507. Flow proceeds from block 806 to decisionblock 1507. At decision block 1507, control logic 244 of FIG. 2determines whether relevant bits in CSR 226 have been changed by thecopy to CSR 226 at block 806. If so flow proceeds to block 808 as inFIG. 8. Otherwise, flow proceeds to block 816, as shown. The alternateembodiment has the advantage of not unnecessarily discarding alreadyaccumulated random bytes and restarting random byte accumulation. Thatis, if the copy to CSR 226 did not change any of the values affectingthe generation of random numbers by RNG unit 136, then there is no needto discard already accumulated random bytes and restart random byteaccumulation since the random bytes were generated using the desiredcontrol values. In one embodiment, the relevant CSR 226 bits are stringfilter enable bit 334, gen select bit 336, CNT enable bit 342, andstring filter max_cnt 346.

Referring now to FIG. 16, a block diagram illustrating operation ofmicroprocessor 100 of FIG. 1 when executing an XSTORE instructionaccording to an alternate embodiment of the present invention is shown.The XSTORE instruction of FIG. 16 is similar to the XSTORE instructionof FIG. 12, however in the alternate embodiment of FIG. 16, thedestination operand of the XSTORE instruction of FIG. 16 specifies aregister of microprocessor 100, such as an XMM register or afloating-point register or an MMX register or one of the integer unitregisters, such as EBX, rather than specifying an address in systemmemory. That is, the valid random data bytes are atomically written intoone of the user-visible registers in register file 108, rather thanbeing stored to system memory. In the example of FIG. 16, the XSTOREinstruction specifies the XMM3 register 376 register of SSE registers352 of FIG. 3 to write the valid random data bytes into, as shown.Advantageously, like the XSTORE instruction of FIG. 12, the XSTOREinstruction of FIG. 16 atomically writes the random data bytes into theuser-visible register along with loading the count to EAX 1202 tofacilitate multitasking operation with RNG unit 136. That is, the XSTOREinstruction of FIG. 16 is also not interruptible.

Referring now to FIG. 17, a block diagram illustrating operation ofmicroprocessor 100 of FIG. 1 when executing an XSTORE instructionaccording to an alternate embodiment of the present invention is shown.The XSTORE instruction of FIG. 17 is similar to the XSTORE instructionof FIG. 12, however in the alternate embodiment of FIG. 17, the XSTOREinstruction includes an x86 architecture REP prefix. With the REP XSTOREinstruction, the count of bytes of random data to be stored to systemmemory is specified as an input parameter in the ECX register 1702 ofregister file 108, as shown. Software loads into ECX 1702 the desiredcount of random data bytes to be stored to system memory prior toexecuting the REP XSTORE instruction.

In one embodiment, the REP XSTORE is interruptible between stores ofrandom data bytes to system memory. The memory address is initiallyspecified in general purpose registers of register file 108. In theexample of FIG. 17, the memory address is specified in ES:EDI 1704 ofregister file 108, as shown. Each time one or more random data bytes arewritten to system memory, ES:EDI 1702 is updated to the next location insystem memory where the random data bytes are to be stored.Additionally, each time one or more random data bytes are stored tosystem memory, ECX 1702 is updated to reflect the number of random bytesremaining to be stored. Assume, for example, a REP XSTORE instructionspecifies in ECX 1702 a byte count of 28 and a memory address of0x12345678. Assume the RNG unit 136 has 8 bytes available in one of buf0242 and buf1 246 and writes the 8 bytes to system memory while morerandom data bytes are accumulating. When the 8 bytes are written tomemory, ECX 1702 is updated to 20 to indicate that 20 more random databytes must be written to system memory. Additionally, the address isupdated to 0x12345680 as the next location in system memory where thenext chunk of random data bytes will be written. An interrupt may occurat this point, and software can examine the updated values. When theinterrupt has been serviced and control is returned to the REP XSTOREinstruction, the REP XSTORE will resume execution using the updatedvalues in ECX 1702 and ES:EDI 1704. In addition, at completion of theREP XSTORE instruction, the current value of CSR 226 of FIG. 2 is copiedto the EAX register 1202 of register file 108.

Although the present invention and its objects, features, and advantageshave been described in detail, other embodiments are encompassed by theinvention. For example, although the invention has been described withreference to SSE registers which are saved and restored by the operatingsystem, the invention is adaptable to employ other registers that aresaved and restored by the operating system to determine whether apossible task switch has occurred and to restore the control register inthe random number generator, such as floating point registers. Also,although the invention has been described with respect to x86architecture processors, the invention is adaptable to various processorarchitectures.

Those skilled in the art should appreciate that they can readily use thedisclosed conception and specific embodiments as a basis for designingor modifying other structures for carrying out the same purposes of thepresent invention without departing from the spirit and scope of theinvention as defined by the appended claims.

1. A macroinstruction executable by a microprocessor for storing randomnumbers from the microprocessor to a memory coupled to themicroprocessor, the instruction comprising: an opcode; a first field,for storing a first operand, said first operand specifying an address inthe memory for storing zero or more bytes of random data generated by arandom number generator comprised in the microprocessor; and a secondfield, for storing a second operand; said second operand specifying aregister comprised in the microprocessor, said register storing saidzero or more bytes of random data to be stored in the memory.
 2. Themacroinstruction of claim 1, wherein said opcode has a predeterminedvalue.
 3. The macroinstruction of claim 2, wherein said predeterminedvalue is 0x0F0xA7.
 4. The macroinstruction of claim 1, wherein themicroprocessor stores a variable number of said zero or more bytes ofrandom data unspecified by the macroinstruction.
 5. The macroinstructionof claim 4, wherein the microprocessor also stores a count to the memoryalong with said zero or more bytes of random data, said count specifyingsaid variable number of said zero or more bytes of random data stored tothe memory.
 6. The macroinstruction of claim 5, wherein themicroprocessor stores said count to the memory at said memory address,and stores said zero or more bytes of random data adjacent to saidcount.
 7. The macroinstruction of claim 4, wherein the microprocessoralso loads a count into a second register of the microprocessor, saidcount specifying said variable number of said zero or more bytes ofrandom data stored to the memory.
 8. The macroinstruction of claim 7,wherein said second register is a general-purpose register of themicroprocessor.
 9. The macroinstruction of claim 8, wherein saidgeneral-purpose register is an EAX register.
 10. The macroinstruction ofclaim 1, wherein the macroinstruction is not interruptible.